package com.zhuoshi.action;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.zhuoshi.bean.Wd_ht_customerModel;
import com.zhuoshi.service.Wd_ht_customerModelService;

@Controller
@RequestMapping("/customer")
public class Wd_ht_customerAction {
	@Autowired
	private Wd_ht_customerModelService customerModelService;
	
	
	@RequestMapping("toadd.do")
	public String hui(){
		return "Wd_Customer_add";
	}
	
	//查询全部
	@RequestMapping("selectAll.do")
	public String selectAll(Wd_ht_customerModel bean,Model model){
		if (bean.getCustomerName() != null && "".equals(bean.getCustomerName().trim())) {
			bean.setCustomerName(null);
		}
		if (bean.getAddress() != null && "".equals(bean.getAddress().trim())) {
			bean.setAddress(null);
		}
		List<Wd_ht_customerModel> customerList = customerModelService.selectAllCustomer(bean);
		model.addAttribute("cuslist", customerList);
		return "Wd_Customer_select";
	}
	
	//添加
	@RequestMapping("add_customer.do")
	public String insertCustomer(Wd_ht_customerModel customerBean){
		//存修改时间
		customerBean.setUpdateTime(new Date());
		customerModelService.insertSelective(customerBean);
		return "redirect:selectAll.do";
	}
	
	//删除
	@RequestMapping("delete_customer.do")
	public String deleteCustomer(String customerId){
		System.out.println(customerId+"------------");
		customerModelService.deleteByPrimaryKey(customerId);
		return "redirect:selectAll.do";
		
	}
	
	//查询数据 并跳转到修改页面
	@RequestMapping("toupdate_customer.do")
	public String updatejsp(Wd_ht_customerModel customerBean,Model model){
		Wd_ht_customerModel customerModel = customerModelService.selectByPrimaryKey(customerBean.getCustomerId());
		System.out.println(customerBean.getCustomerId()+"uuid***********");
		//将查到的数据存到域中
		model.addAttribute("customerById", customerModel);
		return "Wd_Customer_update";
	}
	
	//修改
	@RequestMapping("update_customer.do")
	public String updateCustomer(Wd_ht_customerModel customerBean){
		customerBean.setUpdateTime(new Date());
		customerModelService.updateByPrimaryKeySelective(customerBean);
		return "redirect:selectAll.do";
	}
	
	//查询
//		@RequestMapping("select_customer.do")
//		public String selectAll(Wd_ht_customerModel customerBean,Model model){
//			if (customerBean.getCustomerName() != null && "".equals(customerBean.getCustomerName().trim())) {
//				customerBean.setCustomerName(null);
//			}
//			if (customerBean.getAddress() != null && "".equals(customerBean.getAddress().trim())) {
//				customerBean.setAddress(null);
//			}
//			List<Wd_ht_customerModel> customerList = customerModelService.selectAllCustomer(customerBean);
//			model.addAttribute("cuslist", customerList);
//			return "redirect:select_customer.do";
//		}
	@RequestMapping("select_customerName.do")
	public String selectName(Model model){
		List<Wd_ht_customerModel> customerList = customerModelService.selectAllCustomer();
		for (Wd_ht_customerModel wd_ht_customerModel : customerList) {
			System.out.println(wd_ht_customerModel.getCustomerName()+"+++++++++");
		}
		model.addAttribute("cus", customerList);
		return "Wd_reception_add";
	}
}
